package Bsepuer.command;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

import BesuperApp.pojo.Player;
import Bsepuer.command.impl.AcceptCommand;
import Bsepuer.command.impl.AnswerCommand;
import Bsepuer.command.impl.AskCommand;
import Bsepuer.command.impl.ExitCommand;
import Bsepuer.command.impl.ListQuestionCommand;
import Bsepuer.command.impl.ScoreCommand;

public class PlayerCommandFactory extends SystemCommandFactory {

	private static Map<CommandCode,Class<? extends Command>> playerCommandMap=new HashMap<>();
	static {
		playerCommandMap.put(CommandCode.ASK, AskCommand.class);
		playerCommandMap.put(CommandCode.LIST, ListQuestionCommand.class);
		playerCommandMap.put(CommandCode.ANSWER, AnswerCommand.class);
		playerCommandMap.put(CommandCode.SCORE, ScoreCommand.class);
		playerCommandMap.put(CommandCode.ACCEPT, AcceptCommand.class);
		playerCommandMap.put(CommandCode.EXIT, ExitCommand.class);
	}
	private Player player;

	public PlayerCommandFactory(Player player) {
		this.player = player;
	}

	@Override
	public Command buildCommand(CommandCode cmdCode) {
		Class<?extends Command> cmdClass =playerCommandMap.get(cmdCode);
		if(cmdClass==null){
			return super.buildCommand(cmdCode);
		}
        Command command =null;
        try {
			command = cmdClass.getConstructor(Player.class).newInstance(player);
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		}
		
		
		return command;
	}

}
